//
//  CYFinanceInvestBalanceCell.m
//  cyjf
//
//  Created by tauCross on 2017/9/26.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYFinanceInvestBalanceCell.h"



@implementation CYFinanceInvestBalanceCellObject

@end



@interface CYFinanceInvestBalanceCell ()

@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *balanceLabel;
@property(nonatomic, strong)UIView *line;

@end


@implementation CYFinanceInvestBalanceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.text = @"可用余额";
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        self.titleLabel.textColor = HEXCOLOR(@"444444");
        [self.titleLabel sizeToFit];
        [self.contentView addSubview:self.titleLabel];
        
        self.balanceLabel = [[UILabel alloc] init];
        self.balanceLabel.font = [UIFont systemFontOfSize:14];
        self.balanceLabel.textColor = HEXCOLOR(@"999999");
        [self.contentView addSubview:self.balanceLabel];
        
        self.line = [UIView cy_lineWithColor:HEXCOLOR(@"ECECEC")];
        [self.contentView addSubview:self.line];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 50;
}

- (BOOL)shouldUpdateCellWithObject:(CYFinanceInvestBalanceCellObject *)object
{
    if(object.balance)
    {
        self.balanceLabel.text = [NSString stringWithFormat:@"%@元", object.balance.amountString];
    }
    else
    {
        self.balanceLabel.text = @"";
    }
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.titleLabel.left = 20;
    self.titleLabel.centerY = self.contentView.height / 2;
    
    [self.balanceLabel sizeToFit];
    self.balanceLabel.right = self.contentView.width - 20;
    self.balanceLabel.centerY = self.contentView.height / 2;
    
    self.line.width = self.contentView.width - 20;
    self.line.height = 1 / SCREEN_SCALE;
    self.line.right = self.contentView.width;
    self.line.bottom = self.contentView.height;
}

@end
